﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ParallelRuntimeLibrary.Collections;
using ParallelRuntimeLibrary;
using System.Diagnostics;

namespace TestProject
{
    static class CombinableTester
    {
        static Combinable<List<string>> X;
        public static void Start()
        {
            X = new Combinable<List<string>>();

            Task[] Ts = new Task[8];
            for (int i = 0; i < Ts.Length; i++)
                Ts[i] = new Task(ThreadWork, i.ToString());

            Stopwatch SW = new Stopwatch();
            SW.Start();

            TaskManager.WaitAll(Ts);

            var Result = X.Combine(C);

            SW.Stop();

            //for (int i = 0; i < Result.Count; i++)
            //    Console.WriteLine(Result[i]);


            Console.WriteLine(SW.ElapsedMilliseconds);
            Console.ReadLine();
        }

        public static void ThreadWork(object str)
        {
            for (int i = 0; i < 1000000; i++)
                X.Local.Add((str as string)  + i.ToString());

            X.Local.Clear();

            for (int i = 0; i < 500000; i++)
                X.Local.Add((str as string) + "  :  " + i.ToString());
        }

        public static void ThreadWork2(object str)
        {
            var local = X.Local;

            for (int i = 0; i < 1000000; i++)
                local.Add((str as string) + i.ToString());

            local.Clear();

            for (int i = 0; i < 500000; i++)
                local.Add((str as string) + "  :  " + i.ToString());
        }

        public static void C(ref List<string> result, List<string> other)
        {
            result.AddRange(other);
        }

    }
}
